<template>
  <el-dialog
    title="数据录入"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="dailyDialog"
  >
    <el-form
      :inline="true"
      ref="dataForm"
      :model="dataForm"
      :rules="dataRule"
      @keyup.enter.native="getDataList()"
      label-width="120px"
    >
      <div class="formAddOrUpdate">
        <div class="box">
          <el-form-item label="日期时间">
            <el-date-picker
              size="mini"
              v-model="dataForm.datetime"
              type="datetime"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间"
              disabled
            />
          </el-form-item>
          <el-form-item label="片区">
            <!--            <el-select v-model="stationOptions.id" placeholder="请选择片区">-->
            <!--              <el-option-->
            <!--                v-for="(item, index) in stationOptions"-->
            <!--                :key="index"-->
            <!--                :label="item.name"-->
            <!--                :value="item.id"-->
            <!--              />-->
            <!--            </el-select>-->
            <el-input
              v-model="stationMsg.flowMeterName"
              placeholder=""
              disabled
            ></el-input>
          </el-form-item>
        </div>
        <div class="box">
          <el-form-item label="正流量行度" prop="positiveFlow">
            <el-input
              autocomplete="off"
              v-model="dataForm.positiveFlow"
              placeholder="请输入正流量行度"
            ></el-input>
          </el-form-item>
          <el-form-item label="负流量行度" prop="negativeFlow">
            <el-input
              autocomplete="off"
              v-model="dataForm.negativeFlow"
              placeholder="请输入负流量行度"
            ></el-input>
          </el-form-item>
        </div>
        <div class="box">
          <el-form-item label="瞬时流量" prop="instantFlow">
            <el-input
              autocomplete="off"
              v-model="dataForm.instantFlow"
              placeholder="请输入瞬时流量"
            ></el-input>
          </el-form-item>
          <!--<el-form-item label="操作员" prop="operator">
            <el-input v-model="dataForm.operator" placeholder="请输入操作员姓名"></el-input>
          </el-form-item>-->
        </div>
        <div class="box1">
          <el-form-item label="备注" prop="remark">
            <el-input
              autocomplete="off"
              type="textarea"
              v-model="dataForm.remarkFlow"
            ></el-input>
          </el-form-item>
        </div>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      stationMsg: {},
      dataForm: {
        id: 0,
        datetime: "",
        // operater: "",
        positiveFlow: "",
        negativeFlow: "",
        instantFlow: "",
        remark: ""
      },
      /*stationOptions: [
          {id: 1, name: "西江（低压）"},
          {id: 2, name: "西江（高压）"},
          {id: 3, name: "水源1"},
          {id: 4, name: "水源2"},
          {id: 5, name: "丹横"},
          {id: 6, name: "建沙"},
          {id: 7, name: "青岐"},
          {id: 8, name: "排灌站"},
          {id: 9, name: "银汇华庭"},
          {id: 10, name: "三水二桥南侧"},
          {id: 11, name: "南江1"},
          {id: 12, name: "南江2"},
          {id: 13, name: "南庄季华路"},
          {id: 14, name: "加压泵站禅城表头"},
          {id: 15, name: "西樵"},
          {id: 16, name: "紫南村总水表"},
          {id: 17, name: "加压泵站入水"},
          {id: 18, name: "加压泵站丹灶表头"},
          {id: 19, name: "东门DN50"}
        ],*/
      dataRule: {
        station: [{ required: true, message: "请选择片区", trigger: "blur" }],
        operator: [
          { required: true, message: "操作员不能为空", trigger: "blur" }
        ],
        positiveFlow: [
          { required: true, message: "正流量行度不能为空", trigger: "blur" }
        ],
        negativeFlow: [
          { required: true, message: "负流量行度不能为空", trigger: "blur" }
        ],
        instantFlow: [
          { required: true, message: "瞬时流量不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    init(dateTime, dataGroup) {
      // this.dataForm.id = id || 0;
      this.dataForm.datetime = dateTime;
      this.stationMsg = dataGroup;
      this.visible = true;
      this.$refs["dataForm"].resetFields();
      // this.dataForm.id = this.stationMsg.id;
      console.log(this.stationMsg);
      console.log("未抄表的时间：" + this.stationMsg.updateTime);
      console.log("id: " + this.dataForm.id);
      console.log("当前抄表时间: " + this.dataForm.datetime);
      console.log("片区id: " + this.stationMsg.id);
      console.log("片区名: " + this.stationMsg.flowMeterName);
      this.$nextTick(() => {
        if (this.dataForm.id) {
          console.log(this.dataForm.id);
          this.dataList = [];
          console.log(this.dataList);
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl("/cms/tbCopyFlowData/save"),
            method: "post",
            data: this.$http.adornData({
              area: this.stationMsg.flowMeterName,
              // areaid: this.dataForm.id || undefined,
              areaid: this.stationMsg.id,
              date: this.dataForm.datetime,
              positiveFlow: this.dataForm.positiveFlow,
              negativeFlow: this.dataForm.negativeFlow,
              instantFlow: this.dataForm.instantFlow,
              remark: this.dataForm.remark
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
